package com.bianmin.Mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.bianmin.Model.Article;
import com.bianmin.Model.Goods;
import com.bianmin.Model.Order;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface OrderMapper extends BaseMapper<Order> {

    //根据订单id查询订单
    @Select("select * from `order` where order_number = #{orderNumber}")
    Order selectOrderByprepayId(@Param("orderNumber") String orderNumber);

    //根据用户id查询用户订单
    @Select("SELECT\n" +
            "    t1.*,\n" +
            "    t2.`name` AS goodsName,\n" +
            "    CASE\n" +
            "        WHEN t1.status = 0 THEN '未支付'\n" +
            "        ELSE '已支付'\n" +
            "    END AS payStatusText\n" +
            "FROM\n" +
            "    `order` t1\n" +
            "JOIN\n" +
            "    goods t2 ON t1.goods_id = t2.id\n" +
            "WHERE\n" +
            "    t1.user_id = #{userId}\n" +
            "ORDER BY\n" +
            "    t1.id DESC\n" +
            "LIMIT\n" +
            "    #{page}, #{pageSize};")
    List<Order> orderList(@Param("userId") String userId, @Param("page") Integer page, @Param("pageSize") Integer pageSize);

    //根据订单id查询文章详情
    @Select("select t2.* from `order` t1 join article t2 on t1.article_id = t2.id where t1.order_number = #{orderNumber}")
    Article selectArticleByOrderId(@Param("orderNumber") String orderNumber);

    //根据订单id查询商品信息
    @Select("select t2.* from `order` t1 join goods t2 on t1.goods_id = t2.id where t1.order_number = #{orderNumber}")
    Goods selectGoodsWithOrderNo(@Param("orderNumber") String orderNumber);

}
